package com.etoak.controller;

import com.etoak.common.core.vo.ResultVO;
import com.etoak.dto.CartDTO;
import com.etoak.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;

    /**
     * 添加，修改菜品
     */
    @PostMapping
    public ResultVO<Object> saveOrUpdate(@RequestBody CartDTO cartDTO){
        cartService.saveOrUpdate(cartDTO);
        return ResultVO.success();
    }

    /**
     * 获取购物车菜品列表
     */
    @GetMapping
    public ResultVO<List<CartDTO>> getList(){
        List<CartDTO> cartDTOList = cartService.getList();
        return ResultVO.success(cartDTOList);
    }

    @DeleteMapping("/dishes/{id}")
    public ResultVO<Object> deleteDishes(@PathVariable String id){
        cartService.deleteDishes(id);
        return ResultVO.success();
    }

    @DeleteMapping
    public ResultVO<Object> clearCart(){
        cartService.deleteCart();
        return ResultVO.success();
    }

}
